$(function () {

    allchaxun(1);

    function allchaxun(pageNum) {
        $.post("beyond/kurseAll",{"pageNum":pageNum},function (data) {
            $(".bianli").empty();
            $(".pagination").empty();
            console.log(data);
            $.each(data.list,function (index,kures) {
                $(".bianli").append($('<div class="col-md-4 col-sm-6  course">\n' +
                    '                <a class="course-box" href="courses_show.html">\n' +
                    '                    <div class="sign-box">\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                        <i class="fa fa-star-o course-follow pull-right"\n' +
                    '                            data-follow-url="/courses/1/follow"\n' +
                    '                            data-unfollow-url="/courses/1/unfollow"  style="display:none"  ></i>\n' +
                    '\n' +
                    '                    </div>\n' +
                    '                    <div class="course-img">\n' +
                    '\n' +
                    '                        <img alt="Linux 基础入门（新版）" src="https://dn-simplecloud.shiyanlou.com/ncn1.jpg">\n' +
                    '\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <div class="course-body">\n' +
                    '                        <span class="course-title" data-toggle="tooltip" data-placement="bottom" title="">'+kures.kuesename+'</span>\n' +
                    '                    </div>\n' +
                    '                    <div class="course-footer">\n' +
                    '                        <span class="course-per-num pull-left">\n' +
                    '                            <i class="fa fa-users"></i>\n' +
                                                    kures.sales      +'\n' +
                    '                        </span>\n' +
                    '                        <span style="float: right">\n' +
                    '                            <p style="margin-right:95px;color: red;font-size: 24px;"><b>￥</b></p>\n' +
                    '                            <span style="float: right;margin-right:52px;margin-top:-44px;font-size: 24px;color: #888888">\n' +
                                                        kures.price      +'\n' +
                    '                            </span>\n' +
                    '                        </span>\n' +
                    '                    </div>\n' +
                    '                </a>\n' +
                    '            </div>'))
            })

            yeshu(data.pageNum,data.navigatepageNums,data.pages);

            $('.pagination a').click(function () {
                var num = $(this).data('num');
                if(num!=pageNum){
                    console.log(num);
                    allchaxun(num);
                }
            })

        })
    }

    function yeshu(pageNum,navigatepageNums,pages) {
        if(pageNum>1){
            $('.pagination').append($('<li class="">\n' +
                '                <a href="javascript:;" aria-label="Previous" data-num="1">\n' +
                '                    <span aria-hidden="true">首页</span>\n' +
                '                </a>\n' +
                '            </li>'))
            $('.pagination').append($('<li class="">\n' +
                '                <a href="javascript:;" aria-label="Previous" data-num="'+(pageNum-1)+'">\n' +
                '                    <span aria-hidden="true">上一页</span>\n' +
                '                </a>\n' +
                '            </li>'))
        }

        $.each(navigatepageNums,function (index,num) {
            if(num==pageNum){
                $('.pagination').append($('<li class="active">\n' +
                    '                <a href="javascript:;" data-num="'+num+'">'+num+'</a>\n' +
                    '            </li>'))
            }else {
                $('.pagination').append($('<li class="">\n' +
                    '                <a href="javascript:;" data-num="'+num+'">'+num+'</a>\n' +
                    '            </li>'))
            }
        })

        if(pageNum<pages){
            $('.pagination').append($('<li class="">\n' +
                '                <a href="javascript:;" aria-label="Previous" data-num="'+(pageNum+1)+'">\n' +
                '                    <span aria-hidden="true">下一页</span>\n' +
                '                </a>\n' +
                '            </li>'))

            $('.pagination').append($('<li class="">\n' +
                '                <a href="javascript:;" aria-label="Previous" data-num="'+pages+'">\n' +
                '                    <span aria-hidden="true">末页</span>\n' +
                '                </a>\n' +
                '            </li>'))
        }
    }
    
})